import pymysql
#连接数据库 并 创建数据表

try:
    conn = pymysql.Connect(
        host="127.0.0.1",
        user="root",
        password="root",
        database="hqyj"
    )
    cursor = conn.cursor()
    create_table_sql ="""
    -- 创建用户表
    CREATE TABLE IF NOT EXISTS tb_users (
     id INT PRIMARY KEY AUTO_INCREMENT,
     username VARCHAR(20) NOT NULL UNIQUE,
     password VARCHAR(20) NOT NULL
);
    """
    cursor.execute(create_table_sql)
    conn.commit()
except:
    print("数据库错误")
finally:
    pass